/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * IFormKeuangan.java
 *
 * Created on 16 Jun 10, 23:00:19
 */
package clinsoftbeta.GUI;

import clinsoftbeta.database.Database;
import com.mysql.jdbc.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Sidiq Prihatno
 */
public class IFormKeuangan extends javax.swing.JInternalFrame {

    DefaultTableModel tbModel;
    String query = "";
    private Statement st;
    private Database db;
    private ResultSet rs;
    String modeOperasi = "";

    /** Creates new form IFormKeuangan */
    public IFormKeuangan() {
        initComponents();
        setVisible(true);
        db = new Database();
        db.koneksiDatabase();
        isikanTabel();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        btnTutup = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbKeu = new javax.swing.JTable();

        setClosable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Keuangan");

        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        jButton1.setText("Total Keuangan");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1);

        btnTutup.setText("Tutup");
        btnTutup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTutupActionPerformed(evt);
            }
        });
        jPanel1.add(btnTutup);

        getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);

        jPanel2.setLayout(new java.awt.BorderLayout());

        tbKeu.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "No. Daftar", "Tanggal", "Administrasi", "Obat", "Total"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tbKeu);

        jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel2, java.awt.BorderLayout.PAGE_START);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnTutupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTutupActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_btnTutupActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        String total;
        try{
         query = "SELECT sum( total ) FROM pendaftaran";
         st = (Statement) db.koneksi.createStatement();
            rs = st.executeQuery(query);
            while (rs.next()) {
                String[] tbData = {rs.getString(1)};
                JOptionPane.showMessageDialog(null,"Total keseluruhan klinik adalah Rp. " + rs.getString(1)+",-");
            
            }
        } catch (SQLException se) {
            se.printStackTrace();
            //System.exit(0);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void isikanTabel() {
        String[] tbHeader = {"No. Pendaftaran" , "Tanggal","Administrasi", "Obat", "Total"};
        tbModel = new DefaultTableModel(null, tbHeader);
//        kosongkanTabel();
        try {
            query = "Select no_daftar, tanggal, administrasi, obat, total  from pendaftaran";
            st = (Statement) db.koneksi.createStatement();
            rs = st.executeQuery(query);
            while (rs.next()) {
                String[] tbData = {rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5)};
                tbModel.addRow(tbData);
            }
        } catch (SQLException se) {
            se.printStackTrace();
            //System.exit(0);
        }
        tbKeu.setModel(tbModel);
        if (tbKeu.getRowCount() > 0) {
            tbKeu.addRowSelectionInterval(0, 0);
            //      tampilkanDiText();
//            aktifText(false);
//            AktifSimpan(false);
        } else {
            //btnBaruActionPerformed(null);
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnTutup;
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tbKeu;
    // End of variables declaration//GEN-END:variables
}
